package Modelo.Controler;


import Modelo.Controler.IContentUser;
import Model.Beans.User;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;
import java.util.Map;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author sixviv
 */
public class InterceptorAutentificador implements Interceptor {

	public void destroy() {}

	public void init() {}

	public String intercept(ActionInvocation actionInvocation) throws Exception {
		Map<String, Object> session = actionInvocation.getInvocationContext().getSession();

		User usuario = (User) session.get( "user" );

		if (usuario == null) {
			return "login";
			//return Action.INPUT;
		}
		else {
			Action action = ( Action ) actionInvocation.getAction();
			if (action instanceof IContentUser) {
				((IContentUser)action).setUsuario(usuario);
			}
			return actionInvocation.invoke();
		}
	}
}

